﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Efcore.MultiTenant
{
    /// <summary>
    /// 数据库配置
    /// </summary>
    public class DbOption
    {
        /// <summary>
        /// 数据库唯一识别号
        /// 与TenantInfo值匹配：
        /// 默认： Other为空：TenantId ;Other不为空：TenantId_Other ;
        /// </summary>
        public string DbKey { get; set; }

        /// <summary>
        /// 数据库连接字符串
        /// </summary>
        public string DbConnectionString { get; set; }
    }

    /// <summary>
    /// 相关租户信息配置,DbOptionList未配置时，读取配置文件数据库连接ConnectionStrings
    /// 单租户时，默认取第一个数据库连接
    /// </summary>
    public class TenantOption 
    { 
        public TenantOption()
        {
            DbOptionList = new List<DbOption>();
        }

        /// <summary>
        /// 多租户类型,默认单租户
        /// </summary>
        public TenantType TenantType { get; set; }

        /// <summary>
        /// 数据库类型,默认mysql
        /// </summary>
        public DbType DbType { get; set; }

        /// <summary>
        /// 实体与表名映射方式；默认与实体名一致
        /// </summary>
        public TableNameType TableNameType { get; set; }

        /// <summary>
        /// 数据库配置选项,为空时，将读取配置文件
        /// </summary>
        public List<DbOption> DbOptionList { get;}

        /// <summary>
        /// DbContext OnConfiguring自定义配置
        /// </summary>
        public Action<DbContextOptionsBuilder> DbContextBuildAction { get; set; }

        ///// <summary>
        ///// DbContext OnModelCreating自定义配置
        ///// </summary>
        //public Action<ModelBuilder> DbModelBuildAction { get; set; }
    }

    /// <summary>
    /// 相关租户信息配置,DbOptionList未配置时，读取配置文件数据库连接ConnectionStrings
    /// 单租户时，默认取第一个数据库连接
    /// </summary>
    public class TenantOption<TDbContext>: TenantOption { }

}
